import Cookies from "js-cookie";

export const Session = {
    "set"(key, val) {
        window.sessionStorage.setItem(key, JSON.stringify(val));
    }, "get"(key) {
        let json = window.sessionStorage.getItem(key);
        if (json == 'undefined') {
            return null;
        }
        return JSON.parse(json);
    }, "remove"(key) {
        window.sessionStorage.removeItem(key);
    }, "clear"() {
        window.sessionStorage.clear();
    },
};

export const LocalStorage = {
    "set"(key, val) {
        window.localStorage.setItem(key, JSON.stringify(val));
    }, "get"(key) {
        let json = window.localStorage.getItem(key);
        if (json == 'undefined') {
            return null;
        }
        return JSON.parse(json);
    }, "remove"(key) {
        window.localStorage.removeItem(key);
    }, "clear"() {
        window.localStorage.clear();
    },
};
export function getToken() {
    return Cookies.get(import.meta.env.VITE_TOKEN)
}

export function setToken(obj) {
    return Cookies.set(import.meta.env.VITE_TOKEN, obj,{expires:7})
}

export function getVal(key) {
    return Session.get(key)
}

export function setLVal(key, obj) {
    return LocalStorage.set(key, obj)
}
export function getLVal(key) {
    return LocalStorage.get(key)
}

export function setVal(key, obj) {
    return Session.set(key, obj)
}

export function removeToken(key) {
    return Cookies.remove(key)
}
